#include "stdafx.h"
#include "Hash.h"


CHash::CHash()
{
}


CHash::~CHash()
{
}

uint CHash::AddPiece( uint sq, uint piece )
{
    value ^= RANDOM64[RANDOM_PIECE + HASH_OFFSET_PIECE(piece, sq)];
    return 0;
}

uint64 CHash::Get( uint color, uint ep, uint flags )
{
    uint64 v = ( IS_WHITE(color) ) ? value ^ RANDOM64[RANDOM_TURN] : value;
    if ( flags & CASTLE_WK ) v ^= RANDOM64[ RANDOM_CASTLE + 0 ];
    if ( flags & CASTLE_WQ ) v ^= RANDOM64[ RANDOM_CASTLE + 1 ];
    if ( flags & CASTLE_BK ) v ^= RANDOM64[ RANDOM_CASTLE + 2 ];
    if ( flags & CASTLE_BQ ) v ^= RANDOM64[ RANDOM_CASTLE + 3 ];
    v ^= ( ep ) ? RANDOM64[RANDOM_ENPASSANT + HASH_FILE[ep]] : 0;
    return v;
}

uint CHash::IsRepetition( ) // detect repetition without taking castles and enpassant information into account
{
    cout << (uint64)(value) << endl;
    if ( ( ( hptr >= 4 ) && ( history[hptr-4] == value ) ) ||
         ( ( hptr >= 6 ) && ( history[hptr-6] == value ) ) ||
         ( ( hptr >= 8 ) && ( history[hptr-8] == value ) ) ) return 1;    
    else return 0;
}

